/**
 * ===========================================
 * Project: qb-common
 * ===========================================
 * Package: com.cyou.qb.common.service.impl
 * 
 * Copyright (c) 2012, CYOU All Rights Reserved.
 * ===========================================
 */
package com.cyou.qb.common.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cyou.nad.datastore.DataList;
import com.cyou.nad.datastore.query.JdbcPageDao;
import com.cyou.qb.common.service.NameValueService;
import com.cyou.qb.face.entity.NameValue;

/**
 * <p>NameValueServiceImpl</p>
 * <p>
 * Description:对T_CODE表进行操作service
 * </p>
 *
 * @author lidongwei
 * @version 
 * @since 2012-10-8
 */
@Service("NameValueServiceImpl")
public class NameValueServiceImpl extends BaseSerivceImpl implements NameValueService {
	@Autowired
	private JdbcPageDao jdbcPageDao;

	/**
	 * Description 
	 * @author lidongwei
	 * @since 2012-9-24 下午7:53:14
	 * @see TODOsome class
	 */
	@Override
	public List<NameValue> findNameValue(int type) {
		String sql = "select name,value " + "from t_code " + "where type = ? order by name asc ";
		List<NameValue> nameValueList = new ArrayList<NameValue>();
		DataList dataList = jdbcPageDao.query(sql, type);
		for (int i = 0; dataList != null && i < dataList.rowCount(); i++) {
			NameValue nameV = new NameValue();
			nameV.setStrName(dataList.getString(i, 0));
			nameV.setStrValue(dataList.getString(i, 1));
			nameValueList.add(nameV);
		}
		return nameValueList;
	}

	/**
	 * Description 根据gamecode获取gamename
	 * @author lidongwei
	 * @since 2012-9-24 下午10:13:52
	 * @see TODOsome class
	 */
	@Override
	public String findGameNameByGameCode(String gameCode) {
		String sql = "select name " + " from t_code " + " where type = 1 and value=? ";
		DataList dataList = jdbcPageDao.query(sql, gameCode);
		String gameName = "";
		if (dataList != null && dataList.rowCount() > 0) {
			gameName = dataList.getString(0, 0);
		}
		return gameName;
	}
}
